#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define P(i) p[i-1]
#define Q(i) q[i]
#define E(i,j) e[(i-1)*(n+1)+j]
#define R(i,j) r[(i-1)*(n+1)+j]
#define W(i,j) w[(i-1)*(n+1)+j]
int main()
{
	int i,j,k,l;
	int n;
	float temp;
	float *p,*q,*e,*w;
	int *r;
	scanf("%d",&n);
	p=(float *)malloc(n*sizeof(float));
	q=(float *)malloc((n+1)*sizeof(float));
	e=(float *)malloc((n+1)*(n+1)*sizeof(float));
	r=(int *)malloc((n+1)*(n+1)*sizeof(int));
	w=(float *)malloc((n+1)*(n+1)*sizeof(float));
	for(i=1;i<=n;i++) scanf("%f",&P(i));
	for(i=0;i<=n;i++) scanf("%f",&Q(i));
	for(i=1;i<=(n+1);i++)
	{
		W(i,i-1)=Q(i-1);
		E(i,i-1)=Q(i-1);
	}
	for(l=1;l<=n;l++)
	{
		for(i=1;i<=(n+1)-l;i++)
		{
			j=i+l-1;
			W(i,j)=W(i,j-1)+P(j)+Q(j);
			E(i,j)=1000000.0;
			for(k=i;k<=j;k++)
			{
				temp=E(i,k-1)+E(k+1,j)+W(i,j);
				if(temp<E(i,j))
				{
					E(i,j)=temp;
					R(i,j)=k;
				}
			}
		}
	}
	printf("E(1,n)=%f\n",E(1,n));
	for(l=1;l<=(n+1);l++)
	{
		for(i=l-1;i<=n;i++)
		{
			printf(" %f ",E(l,i));
		}
		printf("\n");
	}

	for(l=1;l<=(n+1);l++)
	{
		for(i=l-1;i<=n;i++)
		{
			printf(" %f ",W(l,i));
		}
		printf("\n");
	}

	for(l=1;l<=(n+1);l++)
	{
		for(i=l-1;i<=n;i++)
		{
			printf(" %d ",R(l,i));
		}
		printf("\n");
	}
	free(p);
	free(q);
	free(e);
	free(w);
	free(r);
	return 0;
}


		
	
